package com.oa.srms.apps.actions.dormitory;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.oa.srms.apps.actions.BasicAction;
import com.oa.srms.apps.business.dormitory.IBedInfoService;
import com.oa.srms.apps.entity.dormitory.BedInfoValue;

@SuppressWarnings("serial")
public class BedInfoAction extends BasicAction {
	
	@Autowired
	private IBedInfoService bedInfoService;
	
	private List<BedInfoValue> bedInfoList;
	
	private Integer id;
	private String ids;
	private String building;
	private String roomNo;
	private Integer bedNo;
	private Integer grade;
	private Integer classNo;
	private String gender;
	private Integer states;
	private String str;
	
	public String toQuery() throws Exception{
		if("".equals(building))
			building = null;
		if("".equals(roomNo))
			roomNo = null;
		if("".equals(grade))
			grade= null;
		if("".equals(classNo))
			classNo = null;
		if("".equals(states))
			states = null;
		
		totalpage= bedInfoService.getTotalPageNumber(building, roomNo, grade, classNo, states, rows);
		count = bedInfoService.getTotalNumber();
		bedInfoList = bedInfoService.queryBedInfo(building, roomNo, grade, classNo, states, rows, currpage);
		return "toQueryPage";
	}
	
	public String addOrModify() throws Exception{
		try{
			if(id != null && !"".equals(id)){
				bedInfoService.modifyBedInfo(id, building, roomNo, bedNo, grade, classNo, gender);
			}else{
				bedInfoService.addBedInfo(building, roomNo, bedNo, grade, classNo, gender);
			}
		}catch(Exception e){
			str = "-1";
		}
		str = "1";
		response.setContentType("text/html; charset=UTF-8");
		response.setHeader("Cache-Control", "no-cache");
		response.getWriter().write(str);
		return null;
	}
	
	public String delete() throws Exception {
		if(id != null)
			bedInfoService.deleteBedInfo(id);
		if(ids != null){
			String[] idArr = ids.split(",");
			for(String idItem : idArr){
				bedInfoService.deleteBedInfo(Integer.parseInt(idItem));
			}
		}
		return "toQuery";
	}
	
	public String toEnable() throws Exception{
		bedInfoService.toEnable(id);
		return "toQuery";
	}
	
	public String toDisable() throws Exception{
		bedInfoService.toDisable(id);
		return "toQuery";
	}
	
	
	// Getter and Setter

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getBuilding() {
		return building;
	}

	public void setBuilding(String building) {
		this.building = building;
	}

	public String getRoomNo() {
		return roomNo;
	}

	public void setRoomNo(String roomNo) {
		this.roomNo = roomNo;
	}

	public Integer getBedNo() {
		return bedNo;
	}

	public void setBedNo(Integer bedNo) {
		this.bedNo = bedNo;
	}

	public Integer getGrade() {
		return grade;
	}

	public void setGrade(Integer grade) {
		this.grade = grade;
	}

	public Integer getClassNo() {
		return classNo;
	}

	public void setClassNo(Integer classNo) {
		this.classNo = classNo;
	}

	public String getGender() {
		return gender;
	}

	public void setGender(String gender) {
		this.gender = gender;
	}

	public Integer getStates() {
		return states;
	}

	public void setStates(Integer states) {
		this.states = states;
	}

	public List<BedInfoValue> getBedInfoList() {
		return bedInfoList;
	}

	public void setBedInfoList(List<BedInfoValue> bedInfoList) {
		this.bedInfoList = bedInfoList;
	}

	public String getStr() {
		return str;
	}

	public void setStr(String str) {
		this.str = str;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}
	
	
}
